

$(document).ready(function(){
	var check=function(input,errorName,pat,length){
		var string = input;
		var error = $("#"+errorName);
		console.log(string.length+"     "+string+"   "+errorName+"  "+pat);
		var p =/[a-z]/g;
		if(string.length==0){error.text(""); return;}
		if(string.length>length){  error.text("长度超过"+length); return;}
		else if(p.test(string[string.length-1])) {error.text("请输入数字");}
		else{
			if(!pat.test(string)){
				error.text("数据格式错误"); return;
			}
			error.text("");
			
	
		}
		
	};
  
	function checkNumber(number,errorName,max){
         var error = $("#"+errorName);
 		if(number.length==0){error.text("");return;}
         var p =/[a-z]/g;
         if(p.test(number[number.length-1])){error.text("请输入数字");return;}
         if(number>max){ error.text("超过"+max);return;}
         if(number<-max){error.text("小于-"+max);return;}
         error.text("");
         
	}
	
/*	
	var inputPosition = $("#Position2");
	var errorPosition = $("#Position2Error");
	var inputDistance2=$("#Distance2Bank2");
	var errorDistance2 = $("#Distance2Bank2Error");
	inputPosition.keyup(function (){
		var string = inputPosition.val();
		if(string.length == 0 || string == "左岸" || string == "右岸" || string == "中间"){
			errorPosition.text("");
		}
		else{
			errorPosition.text("数据格式错误");
		}
	});
	
	inputDistance2.keyup(function (){
		var string = inputDistance2.val();
		if(string.length==0){
			errorDistance2.text("");
             return;
        }
		if(string.length>10) {errorDistance2.text("长度超过10位"); return;}
		var pat=/^\d{1,10}/g;
		if(!pat.test(string)){
			errorDistance2.text("数据格式错误"); return;
		}
		errorDistance2.text("");
	});
*/
	
	var inputArray = ["StartLongitude1","StartLatitude1","EndLongitude1","EndLatitude1","LongitudeDot","LatitudeDot","StartLongitude3","StartLatitude3","EndLongitude3","EndLatitude3"];
	for(var i = 0; i<inputArray.length;i++){
		var tagName = "#"+inputArray[i];
		var tag = $(tagName);
		if(i%2==0)
			tag.keyup(function(){
				checkNumber($(this).val(),$(this).eq(0).attr('id')+"Error",180);
			});
		else tag.keyup(function(){
			checkNumber($(this).val(),$(this).eq(0).attr('id')+"Error",90);
		});
		
	}

/*	
	
	$("#Institution1").keyup(function(){
		var str = $(this).val();
		var error = $("#Institution1Error");
		if(str.length == 0){error.text(""); return;}
		if(str.length==60){error.text("最多60个字符");return;}
	});
	
	$("#Investigator1").keyup(function(){
		var str = $(this).val();
		var error = $("#Investigator1Error");
		if(str.length == 0){error.text(""); return;}
		if(str.length==40){error.text("最多40个字符");return;}
	});
	
	$("#Site1").keyup(function(){
		var str = $(this).val();
		var error = $("#Site1Error");
		if(str.length == 0){error.text(""); return;}
		if(str.length==200){error.text("输入数据不超过200");return;}
	});
	
	$("#River1").keyup(function(){
		var str = $(this).val();
		var error = $("#River1Error");
		if(str.length == 0){error.text(""); return;}
		if(str.length==20){error.text("已输入20个字符");return;}
	});
	
	$("#Weather1").keyup(function(){
		var str = $(this).val();
		var error = $("#Weather1Error");
		if(str.length == 0){error.text(""); return;}
		if(str.length>4){error.text("输入数据超过4");return;}
	});
	
	$("#Temperature1").keyup(function(){
		var pat=/^\d{0,4}\.\d{0,2}/g;
		var error = $("#Temperature1Error");
		if(!pat.test($(this).val())){
			error.text("数据格式错误"); return;
		}
		error.text("");
		
	});
	
	
*/

	$("#Depath").keyup(function(){
		var pat=/^\d{1,5}[\.]{0,1}\d{0,2}/g;
		var error = $("#DepathError");
		if($(this).val().length==0) {error.text("");return;}
		if(!pat.test($(this).val())){
			error.text("数据格式错误"); return;
		}
		error.text("");
	});
	
	$("#waterWarm").keyup(function(){
		var pat=/^\d{1,5}[\.]{0,1}\d{0,2}/g;
		var error = $("#waterWarmError");
		if($(this).val().length==0) {error.text("");return;}
		if(!pat.test($(this).val())){
			error.text("数据格式错误"); return;
		}
		error.text("");
	});
	
	$("#waterHeight").keyup(function(){
		var pat=/^\d{1,5}[\.]{0,1}\d{0,2}/g;
		var error = $("#waterHeightError");
		if($(this).val().length==0) {error.text("");return;}
		if(!pat.test($(this).val())){
			error.text("数据格式错误"); return;
		}
		error.text("");
	});
	
	
	$("#waterFlow").keyup(function(){
		var pat=/^\d{1,10}[\.]{0,1}\d{0,2}/g;
		var error = $("#waterFlowError");
		if($(this).val().length==0) {error.text("");return;}
		if(!pat.test($(this).val())){
			error.text("数据格式错误"); return;
		}
		error.text("");
	}); 
	
	function checkLength(string,errorString,Length){
		var error = $(errorString);
		if(string.length>Length){error.text("字符超过"+Length+"位");return;}
		if(string.length==0){error.text(""); return;}
		error.text("");
	}

	$("#Name").keyup(function(){
		checkLength($(this).val(),"#NameError",40);
	});
	
	$("#NetsModel").keyup(function(){
		checkLength($(this).val(),"#NetsModelError",8);

	});
	
	function checkTime(string,errorString){
		var error = $(errorString);
		console.log("   3   "+errorString);
		pat =/^\d{1,2}:\d{1,2}:\d{1,2}/g;
		if(string.length==0) {error.text("不能为空");return;}
		if(!pat.test(string)){
			error.text("时:分:秒格式");
			return;
		}
		error.text("");
	}
	
	var Mon = ["StartTime","EndTime"];
	for(var i = 0 ;i<Mon.length;i++){
		var tag = "#"+Mon[i];
		console.log(tag);
		var select = $(tag);
		select.keyup(function(){
		    checkTime($(this).val(),"#"+$(this).eq(0).attr('id')+"Error");
		});
	}
	
	$("#NetMouthArea").keyup(function(){
		check($(this).val(),"NetMouthAreaError",/^\d{1,7}[\.]{0,1}\d{0,3}/g,10);
	});
	$("#NetMouthVelocity").keyup(function(){
		check($(this).val(),"NetMouthVelocityError",/^\d{1,7}[\.]{0,1}\d{0,3}/g,10);
	});
	
	$("#NetMouthDip").keyup(function(){
		check($(this).val(),"NetMouthDipError",/^\d{1,3}/g,3);
	});
	
	$("#NameGet").keyup(function(){
		checkLength($(this).val(),"#NameGetError",30);
	});
    
	$("#TotalQuality").keyup(function(){
		check($(this).val(),"TotalQualityError",/^\d{1,8}[\.]{0,1}/g,8);
	});
	
	$("#EggQuality").keyup(function(){
		check($(this).val(),"EggQualityError",/^\d{1,8}[\.]{0,1}/g,8);
	});
	
	$("#FryQuality").keyup(function(){
		check($(this).val(),"FryQualityError",/^\d{1,8}[\.]{0,1}/g,8);
	});
	
	$("#BodyLength").keyup(function(){
		check($(this).val(),"BodyLengthError",/^\d{1,10}/g,10);
	});
	
	$("#Length").keyup(function(){
		check($(this).val(),"LengthError",/^\d{1,10}/g,10);
	});
	
	$("#BodyWeight").keyup(function(){
		check($(this).val(),"BodyWeightError",/^\d{1,10}/g,10);
	});
	
	$("#Age").keyup(function(){
		check($(this).val(),"AgeError",/^\d{1,2}/g,2);
	});
	
	$("#Period").keyup(function(){
		checkLength($(this).val(),"#PeriodError",50);
	});
	
	$("#Diameter").keyup(function(){
		check($(this).val(),"DiameterError",/^\d{0,8}[\.]{0,1}\d{1,2}/g,10);
	});
	$("#EMDiameter").keyup(function(){
		check($(this).val(),"EMDiameterError",/^\d{0,8}[\.]{0,1}\d{1,2}/g,10);
	});
	$("#PigmentProp").keyup(function(){
		checkLength($(this).val(),"#PigmentPropError",100);
	});
	$("#EmbryoProp").keyup(function(){
		
		checkLength($(this).val(),"#EmbryoPropError",100);
	});
	
});